 <script type="text/javascript">
     $(function () {
        $('[data-toggle="tooltip"]').tooltip();
    })
        $("#importrecords").bind("click",function(){
          $("#fileToUpload").click();
        });

        function fileSelected(fileToUpload) {
            var file = document.getElementById(fileToUpload).files[0];
            if (file) {
                $(".progress").show();
                var fd = new FormData();
                fd.append("fileToUpload", document.getElementById(fileToUpload).files[0]);
                fd.append("userid",{$userid});
                var xhr = new XMLHttpRequest();
                xhr.upload.addEventListener("progress", uploadProgress, false);
                xhr.addEventListener("load", uploadComplete, false);
                xhr.addEventListener("error", uploadFailed, false);
                xhr.addEventListener("abort", uploadCanceled, false);
                xhr.open("POST", "__APP__/Medicalrecord/importrecords");//修改成自己的接口
                xhr.send(fd);
            }
        }

        function uploadProgress(evt) {
            if (evt.lengthComputable) {
                var percentComplete = Math.round(evt.loaded * 100 / evt.total);
                //document.getElementById('progressNumber').innerHTML = percentComplete.toString() + '%';
                $(".progress-bar").css("width",function(){return percentComplete.toString() + '%'});
                $(".progress-bar").text(percentComplete.toString() + '%');
            }else {
                document.getElementById('progressNumber').innerHTML = 'unable to compute';
            }
        }
            
        function uploadComplete(evt) {
            /* 服务器端返回响应时候触发event事件*/
            //alert(evt.target.responseText);
            var res= JSON.parse(evt.target.responseText);
            if(res.status==1){
                alert('导入成功');
                $(".progress").hide();
                var file = $("#fileToUpload") 
                file.after(file.clone().val("")); 
                file.remove();
                editurl('__APP__/Medicalrecord/user/id/{$userid}/pubtype/1');
            }else{
                alert(res.msg);
                var file = $("#fileToUpload") 
                file.after(file.clone().val("")); 
                file.remove();
            }
        }
        function uploadFailed(evt) {
            alert("There was an error attempting to upload the file.");
        }
        function uploadCanceled(evt) {
            alert("The upload has been canceled by the user or the browser dropped the connection.");
        }


 </script>

 <div class="row">
                <div class="col-lg-12">
                    <h3 class="page-header"><i class="fa fa-chevron-left" onclick="closeurl();"></i>用户病例管理</h3>
                </div>
                <!-- /.col-lg-12 -->
            </div>

            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-green">
                        <div class="panel-heading">
                            用户简介
                        </div>
                        <div class="panel-body">
                            <div class="media">
                              <div class="media-left">
                                <a href="#">
                                  <img class="media-object" src="<if condition="$user.image eq ''">{$user.headimgurl}<else />{$user.image}</if>" alt="用户头像" width="100">
                                </a>
                              </div>
                              <div class="media-body">
                                <h4 class="media-heading"><b>{$user.name}</b></h4>
                                <p>
                                {:L('hospital')}:{$user.hospital}
                                {:L('address')}:{$user.address}
                                </p>
                                <p>
                                {:L('department')}:{$user.department}
                                {:L('position')}:{$user.position}
                                {:L('socialposition')}:{$user.socialposition}
                                </p>
                                <p>
                                {:L('mobile')}:{$user.mobile}
                                {:L('email')}:{$user.email}
                                所在省份:{$user.doctorprovince}
                                </p>
                              </div>
                            </div>  
                        </div>
                        <div class="panel-footer">
                            <button type="button" onclick = "editurl('__APP__/Medicalrecord/user/id/{$userid}/pubtype/2');" class="btn btn-primary btn-sm">已发布病例</button>
                            <button type="button" onclick = "editurl('__APP__/Medicalrecord/user/id/{$userid}/pubtype/1');" class="btn btn-info btn-sm">存草稿病例</button>
                            <button type="button" onclick = "editurl('__APP__/Medicalrecord/user/id/{$userid}/pubtype/3');" class="btn btn-danger btn-sm">已屏蔽病例</button>
                            <button type="button" onclick = "editurl('__APP__/Medicalrecord/add/userid/{$userid}/pubtype/{$pubtype}/p/{$currentpage}');" class="btn btn-success btn-sm">添加新病例</button>
                            <button type="button" id="importrecords" class="btn btn-warning btn-sm">导入病例库</button>
                            <div class="progress" style="display:none;width:200px;margin-top:12px;">
                                <div class="progress-bar" role="progressbar" aria-valuenow="60" aria-valuemin="0" aria-valuemax="100" style="width: 60%;">
                                    60%
                                </div>
                            </div>
                            <input type="file" name="fileToUpload" accept=".csv" id="fileToUpload" onchange="fileSelected('fileToUpload');" style="display:none;"/>
                            <button type="button" onclick = "editurl('__APP__/Medicalrecord/report/id/{$userid}');" class="btn btn-danger btn-sm">病例分享单个病例报告1</button>
                        </div>
                    </div>
              
                </div>
                <div class="col-lg-12"> </div>   
            </div>
            <!-- /.row -->
            <div class="row">
                <div class="col-lg-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <if condition="$pubtype eq 1">存草稿病例列表<elseif condition="$pubtype eq 2" />已发布病例列表<else />已屏蔽病例列表</if>
                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="dataTable_wrapper">
                                <table class="table table-striped table-bordered table-hover">
                                    <thead>
                                        <tr>
                                            <th><center>{:L('is_pics')}</center></th>
                                            <th><center>{:L('diagnostic')}</center></th>
                                            <th><center>{:L('major')}</center></th>
                                            <th><center>{:L('tp')}</center></th>
                                            <th><center>{:L('cashtype')}</center></th>
                                            <th><center>操作</center></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <volist name="list" id="vo">
                                        <tr class="odd gradeX">
                                            <td><center><img src="{$vo.image}" width="50"></center></td>
                                            <td style="vertical-align: middle;"><center>{$vo['diagnostic']}</center></td>
                                            <td style="vertical-align: middle;"><center>{$vo['major']}</center></td>
                                            <td class="center" style="vertical-align: middle;"><center>{$vo['tp']}</center></td>
                                            <td style="vertical-align: middle;">
                                                <center>
                                                    <if condition="$vo.cashtype eq 1">免费
                                                    <else />收费
                                                    </if>
                                                </center>
                                            </td>
                                            <td class="center" style="vertical-align: middle;">
                                                <center>
                                                    <button type="button" class="btn btn-success btn-xs"  data-toggle="tooltip" data-placement="bottom" title="编辑用户病历" onclick="editurl('__APP__/Medicalrecord/edit/id/{$vo.id}/userid/{$userid}/pubtype/{$pubtype}/p/{$currentpage}');">
                                                        <i class="fa fa-edit"></i>
                                                    </button>
                                                    <if condition="$pubtype eq 1">
                                                    <button type="button" class="btn btn-primary btn-xs"  data-toggle="tooltip" data-placement="bottom" title="发布用户病历" onclick="publish({$vo.id})">
                                                        <i class="fa fa-play"></i>
                                                    </button>
                                                    </if>
                                                    <if condition="$pubtype eq 2">
                                                    <button type="button" class="btn btn-info btn-xs"  data-toggle="tooltip" data-placement="bottom" title="用户病历存草稿" onclick="savetemp({$vo.id})">
                                                        <i class="fa fa-pause"></i>
                                                    </button>
                                                    </if>
                                                </center>
                                            </td> 
                                        </tr>
                                        </volist>
                                    </tbody>
                                </table>
                            </div>
                            <!-- /.table-responsive -->
                        </div>
                        <!-- /.panel-body -->
                    </div>
                    <!-- /.panel -->
                </div>
                <!-- /.col-lg-12 -->
            </div>
            <!-- /.row -->
            {$page}
        </div>

    <!-- Page-Level Demo Scripts - Tables - Use for reference -->
    <script>
    function publish(id){
        $.post('__APP__/Medicalrecord/publish',{id:id},function(data){
            if(data.status==1){
                alert('操作成功');
                editurl('__APP__/Medicalrecord/user/id/{$userid}/pubtype/2');
            }else{
                alert('操作失败');
            }
        });        
    }
     function savetemp(id){
        $.post('__APP__/Medicalrecord/savetemp',{id:id},function(data){
            if(data.status==1){
                alert('操作成功');
                editurl('__APP__/Medicalrecord/user/id/{$userid}/pubtype/1');
            }else{
                alert('操作失败');
            }
        });        
    }   
    </script>

</body>

</html>
